package com.team.merchant.controller;

import com.team.common.core.web.controller.BaseController;
import com.team.common.core.web.domain.AjaxResult;
import com.team.merchant.domain.AccountFlow;
import com.team.merchant.service.IWxVerificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
/*进行核销*/
@RequestMapping("/wxVerification")
public class WxVerificationController extends BaseController
{

    @Autowired
    private IWxVerificationService wxVerificationService;
    @GetMapping("/verification")
    public AjaxResult verification(@RequestParam String verificationCode,@RequestParam Long merchantId){
        // 进行核销，交给service层处理
        AccountFlow accountFlow = wxVerificationService.verification(verificationCode, merchantId);
        if(accountFlow==null){
            return AjaxResult.error("核销失败");
        }
        //TODO 核销成功，返回成功消息，此时需要向rabbitmq当中发送一条消息，告诉订单模块订单已经核销
        wxVerificationService.sendOrderMessage(accountFlow);
        return AjaxResult.success();
    }
    @GetMapping("/record")
    public AjaxResult getRecord(){
        return AjaxResult.success(wxVerificationService.getRecord());
    }

    @GetMapping("/getMerchantId")
    public AjaxResult getMerchantId(@RequestParam Long userId){
        return AjaxResult.success(wxVerificationService.getMerchantId(userId));
    }
}
